import unittest
import requests
import pandas as pd
import ddt

url = "http://127.0.0.1:5000/"

file = pd.read_csv('../data/select_test.csv')
df = pd.DataFrame(file)
data = df.to_dict(orient='records')


# 在测试类上加上装饰器:@ddt.ddt
@ddt.ddt
class SelectTest(unittest.TestCase):
    # 在需要使用数据的方法上加上装饰器:@ddt:data
    @classmethod
    def setUpClass(cls) -> None:
        print("-----开始执行用例Select-----")

    @ddt.data(*data)
    def testSelectOneSuccess(self, data):
        code = 200
        # 结果
        result = requests.post(url=url + "selectOne", data=data).json()
        print(result)
        self.assertEqual(code, result.get("code"))

    def testSelectAll(self):
        # 传递的参数，准备数据
        code = 200
        # 结果
        result = requests.post(url=url + "selectAll").json()
        print(result)
        self.assertEqual(code, result.get("code"))

    @classmethod
    def tearDownClass(cls) -> None:
        print("-----用例Select执行结束-----")
